﻿using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using CE.Database;
/// <summary>
/// Summary description for PACallStatusDB
/// </summary>
/// 
namespace CE.PersonalAccident
{
    public class PACallStatusDB
    {
        public PACallStatusDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(PACallStatus pacallstatus)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCXCRMPACallStatusInsertUpdateSingleItem";
            SortedList _sPara = new SortedList();
            #region Parameter
            _sPara.Add("@CallStatusId", pacallstatus.CallStatusId);
            _sPara.Add("@CarId", pacallstatus.CarId);
            _sPara.Add("@CIProviderCompanyId", pacallstatus.CIProviderCompanyId);
            _sPara.Add("@CustomerId", pacallstatus.CustomerId);
            _sPara.Add("@ContactNo", pacallstatus.ContactNo);
            _sPara.Add("@CIQuoteRefNo", pacallstatus.CIQuoteRefNo);
            _sPara.Add("@AgentId", pacallstatus.AgentId);
            _sPara.Add("@CallStatus", pacallstatus.AgentCallStatus);
            _sPara.Add("@CallTypeId", pacallstatus.CallTypeId);
            _sPara.Add("@Remark", pacallstatus.Remark);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);
            return _result;
        }

        public PACallStatus GetCallStatus(Int64 CarId, Int64 CustomerId)
        {
            PACallStatus _mycallstatus = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCXCRMPACallStatusSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CarId", CarId);
            _spara.Add("@CustomerId", CustomerId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _mycallstatus = new PACallStatus();
                    _mycallstatus = FillDataRecord(_dt, 0);
                }
            }
            return _mycallstatus;
        }

        private PACallStatus FillDataRecord(DataTable myDataTable, int RowId)
        {
            PACallStatus myCallStatus = new PACallStatus();
            myCallStatus.CallStatusId = Convert.ToInt64(myDataTable.Rows[RowId]["CallStatusId"].ToString());
            myCallStatus.CarId = Convert.ToInt64(myDataTable.Rows[RowId]["CarId"].ToString());
            myCallStatus.CustomerId = Convert.ToInt64(myDataTable.Rows[RowId]["CustomerId"].ToString());
            myCallStatus.ContactNo = myDataTable.Rows[RowId]["ContactNo"].ToString();
            myCallStatus.CIQuoteRefNo = myDataTable.Rows[RowId]["CIQuoteRefNo"].ToString();
            myCallStatus.AgentId = Convert.ToInt64(myDataTable.Rows[RowId]["AgentId"].ToString());
            myCallStatus.AgentCallStatus = Convert.ToInt32(myDataTable.Rows[RowId]["CallStatus"].ToString());
            myCallStatus.CallTypeId = Convert.ToInt32(myDataTable.Rows[RowId]["CallTypeId"].ToString());
            myCallStatus.Remark = myDataTable.Rows[RowId]["Remark"].ToString();
            return myCallStatus;
        }

    }
}